extends ../layout

block meta
    link(rel="stylesheet", href="#{options.cdn_path}/js/artDialog/skins/default.css?v=#{options.site_version}")

block content
    // 传递参数
    optionsClass = true
    tab = blog.id ? '修改' : '添加'
    include ../common/_admin_navbar
    .content
        .header
            h1.page-title #{tab}
        ul.breadcrumb
            li
                a(href="/admin") 首页
                span.divider /
            li.active #{tab}
        .container-fluid
            .row-fluid
                form(action="/admin/links/save_update", method="post")
                    input(type="hidden", name="links.id", value="#{links.id}")
                    .btn-toolbar
                        button.btn.btn-primary(type="submit")
                            i.icon-save 
                            | &nbsp;保存
                        a.btn(href="/admin/links") 返回
                        .btn-group
                    .well
                        #myTabContent.tab-content
                            label 网站
                            input.input-xlarge(type="text", name="links.title", value="#{links.title}", required="required")
                            label 分类
                            select#DropDownTimezone.input-xlarge(name="blog.blog_type")
                                types = [{'id': 0, 'type_name': '友链'}, {'id': 1, 'type_name': '广告'}]
                                each item in types
                                    if item.id == links.type
                                        option(value="#{item.id}", selected="selected") #{item.type_name}
                                    else
                                        option(value="#{item.id}") #{item.type_name}
                            label 地址
                            input.input-xxlarge(type="text", name="links.url", value="#{links.url}")
                            label 图标
                            input.input-xxlarge(type="text", name="links.img", value="#{links.img}")

                include ../common/_admin_footer

block script
    script(src="#{options.cdn_path}/js/artDialog/jquery.artDialog.min.js?v=#{options.site_version}")
    script
        $(function(){
            $('form').submit(function(){
                var dialog = $.dialog();
                var title = $('input[name="links.title"]').val();
                var url   = $('input[name="links.url"]').val();
                var img   = $('input[name="links.img"]').val();
                if( title.length < 1 ){
                    dialog.content('网站名不能为空！').time(1000);
                    return false;
                }
                if( url.length < 1 ){
                    dialog.content('链接地址不能为空！').time(1000);
                    return false;
                }
                _post(this, dialog, function(data){
                    if(data.status){
                        dialog.content('保存成功！').lock().time(1000);
                        setTimeout(function(){
                            location.href = '/admin/links';
                        }, 1500);
                    }else{
                        dialog.content('服务器忙，请稍候！').time(2000);
                    }
                })
                return false;
            });
        });